package com.android.canvasproject.model.entity;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.Map;

import android.util.Log;

import com.android.canvasproject.view.utils.ConstantsAction;

public class Person extends GenericEntity {

	private static final long serialVersionUID = 9025622203076700560L;
	
	private Integer id;

	private String name;

	private String occupation;
	
	private String city;
	
	private String state;
	
	private String academicTraining;
	
	private String teachingInstitution;
	
	private String enterprise;
	
	private Date startingLastJob;
	
	private Date endingLastJob;
	
	private String locationLastJob;
	
	private String descriptionLastActivity;

	private String profilePhoto;
	
	public static Person entityStructure(Map<String, Object> map) {
		Person person = new Person();
		
		try{
			SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());

			person.setId((Integer) map.get("_id"));
			person.setName((String) map.get("name"));
			person.setOccupation((String) map.get("occupation"));
			person.setCity((String) map.get("city"));
			person.setState((String) map.get("state"));
			person.setAcademicTraining((String) map.get("academic_training"));
			person.setTeachingInstitution((String) map.get("teaching_institution"));
			person.setEnterprise((String) map.get("enterprise"));
			person.setStartingLastJob(map.get("starting_last_job") == null ? null : format.parse((String) map.get("starting_last_job")));
			person.setEndingLastJob(map.get("ending_last_job") == null ? null : format.parse((String) map.get("ending_last_job")));
			person.setLocationLastJob((String) map.get("location_last_job"));
			person.setDescriptionLastActivity((String) map.get("description_last_activity"));
			person.setProfilePhoto((String) map.get("profile_photo"));

			person.entityStruture(map);

		} catch (ParseException e) {
			Log.e(Person.class.getName(), ConstantsAction.Error.PARSE_ERROR, e);
			throw new org.apache.http.ParseException();

		}

		return person;
	}
	
	public static class PersonDao {
		
		public static final String TB_PERSON = "PERSON";
		
		public static final String[] COLS_PERSON = new String[] { "_id", "name",
			"occupation", "city", "state", "academic_training",
			"teaching_institution", "enterprise", "starting_last_job",
			"ending_last_job", "location_last_job",
			"description_last_activity", "profile_photo", "id_ics",
			"creation_date", "last_sync", "last_notification",
			"local_creation", "is_synchronized" };

		public static final String DB_CREATE_PERSON = "CREATE TABLE IF NOT EXISTS PERSON (_id INTEGER PRIMARY KEY, name VARCHAR(80) NOT NULL, occupation VARCHAR(100) NULL, city VARCHAR(80) NULL,  state VARCHAR(80) NULL, academic_training VARCHAR(80) NULL, teaching_institution VARCHAR (80) NULL, enterprise VARCHAR (80) NULL, starting_last_job DATETIME NULL, ending_last_job DATETIME NULL, location_last_job VARCHAR(100) NULL, description_last_activity TEXT NULL, profile_photo TEXT NULL, id_ics BIGINT UNIQUE, creation_date DATETIME DEFAULT CURRENT_TIMESTAMP, last_sync TIMESTAMP NULL, last_notification TIMESTAMP NULL, local_creation INT DEFAULT 0, is_synchronized INT DEFAULT 0);";
	}
	
	public Person() {
		super();
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getOccupation() {
		return occupation;
	}

	public void setOccupation(String occupation) {
		this.occupation = occupation;
	}

	public String getCity() {
		return city;
	}

	public void setCity(String city) {
		this.city = city;
	}

	public String getState() {
		return state;
	}

	public void setState(String state) {
		this.state = state;
	}

	public String getAcademicTraining() {
		return academicTraining;
	}

	public void setAcademicTraining(String academicTraining) {
		this.academicTraining = academicTraining;
	}

	public String getTeachingInstitution() {
		return teachingInstitution;
	}

	public void setTeachingInstitution(String teachingInstitution) {
		this.teachingInstitution = teachingInstitution;
	}

	public String getEnterprise() {
		return enterprise;
	}

	public void setEnterprise(String enterprise) {
		this.enterprise = enterprise;
	}

	public Date getStartingLastJob() {
		return startingLastJob;
	}

	public void setStartingLastJob(Date startingLastJob) {
		this.startingLastJob = startingLastJob;
	}

	public Date getEndingLastJob() {
		return endingLastJob;
	}

	public void setEndingLastJob(Date endingLastJob) {
		this.endingLastJob = endingLastJob;
	}

	public String getLocationLastJob() {
		return locationLastJob;
	}

	public void setLocationLastJob(String locationLastJob) {
		this.locationLastJob = locationLastJob;
	}

	public String getDescriptionLastActivity() {
		return descriptionLastActivity;
	}

	public void setDescriptionLastActivity(String descriptionLastActivity) {
		this.descriptionLastActivity = descriptionLastActivity;
	}

	public String getProfilePhoto() {
		return profilePhoto;
	}

	public void setProfilePhoto(String profilePhoto) {
		this.profilePhoto = profilePhoto;
	}
}